package com.sky.controller.admin;

import com.sky.dto.AlertDTO;
import com.sky.dto.AlertPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.AlertService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/alert")
@Api(tags = "预警相关接口")
@Slf4j
public class AlertController {
    @Autowired
    private AlertService alertService;
    /**
     * 分页查询
     * @param pageQuery
     * @return
     */
    @RequiresPermissions("管理员")
    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> page(AlertPageQueryDTO pageQuery) {
        PageResult pageResult = alertService.pageQuery(pageQuery);
        return Result.success(pageResult);
    }
    //预警阅读状态修改
    @RequiresRoles("管理员")
    @PutMapping()
    @ApiOperation(value = "预警阅读状态修改")
    public Result process(@RequestBody AlertDTO alertDTO) {
        alertService.process(alertDTO);
        return Result.success();
    }
    /**
     * 修改预警等级和违法类型
     */
    @RequiresPermissions("管理员")
    @PutMapping("/warning")
    @ApiOperation("修改预警等级和违法类型")
    public Result updateWarningLevel(@RequestBody AlertDTO alertDTO) {
        alertService.updateWarningLevel(alertDTO);
        return Result.success();
    }

}
